<?php
  require '../admin/config/config.php';
  mydb_connect();
/* 
 * Copyright (C) 2008 Anis uddin Ahmad <anisniit@gmail.com>
 *
 * This file is part of the "Universal Feed Writer" project.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
* 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

  
  include("../feed/FeedTypes.php");
  
  //Creating an instance of RSS2FeedWriter class. 
  //The constant RSS2 is passed to mention the version
  $TestFeed = new RSS2FeedWriter();
  
  //Setting the channel elements
  //Use wrapper functions for common channel elements
  $TestFeed->setTitle('TechAfghanistan RSS Feed');
  $TestFeed->setLink('http://tech.af/rss/');
  $TestFeed->setDescription('This is the RSS Feed for TechAfghanistan Website');
  
  //Image title and link must match with the 'title' and 'link' channel elements for RSS 2.0
  $TestFeed->setImage('TechAfghanistan','http://tech.af/rss/','http://tech.af/assets/img/logo.png');
  
  //Use core setChannelElement() function for other optional channels
  $TestFeed->setChannelElement('language', 'en-us');
  $TestFeed->setChannelElement('pubDate', date(DATE_RSS, time()));
  
  //Adding a feed. Genarally this portion will be in a loop and add all feeds.
  $result = $conn->query("SELECT * FROM `news` ORDER BY pub_date DESC");
    while($row = $result->fetch())
    {
  //Create an empty FeedItem
  $newItem = $TestFeed->createNewItem();
  
  //Add elements to the feed item
  //Use wrapper functions to add common feed elements
  $newItem->setTitle($row['title']);
  $newItem->setLink('http://tech.af/post/' .  $row['id']);
  //The parameter is a timestamp for setDate() function
  $newItem->setDate($row['pub_date']);
  $newItem->setDescription($row['description']);
  //Use core addElement() function for other supported optional elements
  $newItem->addElement('image','http://tech.af/author/images/' . $row['img_name']);

  //Now add the feed item
  $TestFeed->addItem($newItem);
}
  
  //OK. Everything is done. Now genarate the feed.
  $TestFeed->generateFeed();
  
?>